import 'package:flutter/material.dart';
import '../model/tagModel.dart';
import '../services/tagService.dart';

class TagProvider extends ChangeNotifier {
  final TagService _tagService = TagService();

  List<TagModel> _tags = [];
  bool _isLoading = false;
  String? _error;

  List<TagModel> get tags => _tags;
  bool get isLoading => _isLoading;
  String? get error => _error;

  Future<void> fetchTags() async {
    _isLoading = true;
    _error = null;
    notifyListeners();

    try {
      _tags = await _tagService.getTags();
      print('成功获取到 ${_tags.length} 个标签');
    } catch (e) {
      _error = e.toString();
      print('获取标签失败: $e');
    } finally {
      _isLoading = false;
      notifyListeners();
    }
  }
}
